#include "Drawable.hpp"
using namespace std;

list<Drawable*> Drawable::all_drawables;

Drawable::Drawable(float z) : z_index(z), visible(true)
{
	this->insert();
}


Drawable::~Drawable(void)
{
	all_drawables.remove(this);
}

void Drawable::SetZIndex(float index){

}

void Drawable::insert(){
	std::list<Drawable*>::const_iterator 
	it(all_drawables.begin()), 
    itend(all_drawables.end()); 
	for(;it!=itend;++it){
		if((*it)->z_index > this->z_index){
			all_drawables.insert(it, this);
			return;
		}
	}
	all_drawables.insert(it, this);
}

void Drawable::DrawAll(){
	std::list<Drawable*>::const_iterator 
	it(all_drawables.begin()), 
    itend(all_drawables.end()); 
	for(;it!=itend;++it){
		if((*it)->visible)
			(*it)->Draw();
	}
}